// mixins for button
// ------------------------
.button-size(@height; @padding; @font-size; @border-radius) {
  padding: @padding;
  font-size: @font-size;
  border-radius: @border-radius;
  height: @height;
}

.button-disabled() {

  &.disabled,
  &[disabled] {

    &,
    &:hover,
    &:focus,
    &:active,
    &.active {
      .button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
    }
  }
}

.button-variant-primary(@color; @background) {
  .button-color(@color; @background; @background);

  &:hover,
  &:focus {
    .button-color(@color; tint(@background, 20%); tint(@background, 20%));
  }

  &:active,
  &.active {
    .button-color(@color; shade(@background, 10%); shade(@background, 10%));
  }

  & .btn-active {
    .button-active(@background);
  }


  .button-disabled();
}

.button-variant-other(@color; @background; @border) {
  .button-color(@color; @background; @border);

  &:hover,
  &:focus {
    .button-color(tint(@primary-color, 50%); @background; tint(@primary-color, 50%));
  }

  &:active,
  &.active {
    .button-color(shade(@primary-color, 5%); @background; shade(@primary-color, 5%));
  }

  & .btn-active {
    .button-active(@background);
  }


  .button-disabled();
}

.button-active(@background) {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 1em;
  height: 1em;
  z-index: 1;
  border-radius: 50%;
  background: shade(@background, 20%);
  transform-origin: center center;
  transform: scale(0);
  opacity: .3;
}

.button-color(@color; @background; @border) {
  color: @color;
  background-color: @background;
  border-color: @border;

  // a inside Button which only work in Chrome
  // http://stackoverflow.com/a/17253457
  >a:only-child {
    color: currentColor;

    &:after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      background: transparent;
    }
  }
}

.button-group-base(@btnClassName) {
  //按钮组的基础样式
  position: relative;
  display: inline-block;
  border-radius: 4px;
  font-size: 0;

  >.@{btnClassName},
  >span>.@{btnClassName} {
    position: relative;

    &:hover,
    &:focus,
    &:active,
    &.active {
      z-index: 2;
    }

    &:disabled {
      z-index: 0;
    }
  }
}

// Base styles of buttons
// --------------------------------------------------
.button() {
  vertical-align: middle;
  display: inline-block;
  overflow: hidden;
  font-weight: @btn-font-weight;
  text-align: center;
  touch-action: manipulation;
  cursor: pointer;
  line-height: 1.5;
  background-image: none;
  border: @border-width-base @border-style-base transparent;
  white-space: nowrap;
  .button-size(@btn-height-base; @btn-padding-base; @font-size-base; @btn-border-radius-base);
  user-select: none;
  transition: color @transition-time-base linear, background-color @transition-time-base linear, border @transition-time-base linear, box-shadow @transition-time-base linear;
  position: relative;

  >span {
    transition: display .2s linear;
  }

  &,
  &:active,
  &:focus {
    outline: 0;
  }


  &:not([disabled]):hover {
    text-decoration: none;
  }

  &:not([disabled]):active {
    outline: 0;
  }

  &.disabled,
  &[disabled] {
    cursor: not-allowed;

    >* {
      pointer-events: none;
    }
  }
}

// primary button style
.button-primary() {
  .button-variant-primary(@btn-primary-color; @btn-primary-bg);
}

.button-info() {
  .button-variant-primary(@btn-primary-color; @info-color);
}

.button-success() {
  .button-variant-primary(@btn-primary-color; @success-color);
}

.button-warning() {
  .button-variant-primary(@btn-primary-color; @warning-color);
}

.button-error() {
  .button-variant-primary(@btn-primary-color; @error-color);
}

.button-loading-color(@backgroundColor) {
  cursor: inherit;
  .button-color(@btn-primary-color, tint(@backgroundColor, 40%), tint(@backgroundColor, 40%))
}



// default button style
.button-default() {
  .button-variant-other(@btn-default-color; @btn-default-bg; @btn-default-border);

  &:hover,
  &:focus,
  &:active,
  &.active {
    background: @btn-default-bg;
    text-decoration: none;
  }
}

// dashed button style
.button-dashed() {
  .button-variant-other(@btn-default-color, @btn-default-bg, @btn-default-border);
  border-style: dashed;
}


// circle button: the content only contains icon
.btn-circle(@btnClassName: btn) {
  .square(@btn-circle-size);
  .button-size(@btn-circle-size; 0; @font-size-base + 2px; 50%);
}

// Horizontal button groups styl
// --------------------------------------------------
.button-group(@btnClassName: btn) {
  //按钮组主要是设置里面一排按钮的边框和圆角
  .button-group-base(@btnClassName);

  .@{btnClassName}+.@{btnClassName},
  .@{btnClassName}+&,
  span+.@{btnClassName},
  .@{btnClassName}+span,
  >span+span,
  &+.@{btnClassName},
  &+& {
    margin-left: -1px;
  }

  .@{btnClassName}-primary+.@{btnClassName}:not(.@{btnClassName}-primary):not([disabled]) {
    border-left-color: transparent;
  }

  .@{btnClassName} {
    border-radius: 0;
  }

  >.@{btnClassName}:first-child,
  >span:first-child>.@{btnClassName} {
    margin-left: 0;
  }

  >.@{btnClassName}:only-child {
    border-radius: @btn-border-radius-base;
  }

  >span:only-child>.@{btnClassName} {
    border-radius: @btn-border-radius-base;
  }

  >.@{btnClassName}:first-child:not(:last-child),
  >span:first-child:not(:last-child)>.@{btnClassName} {
    border-bottom-left-radius: @btn-border-radius-base;
    border-top-left-radius: @btn-border-radius-base;
  }

  >.@{btnClassName}:last-child:not(:first-child),
  >span:last-child:not(:first-child)>.@{btnClassName} {
    border-bottom-right-radius: @btn-border-radius-base;
    border-top-right-radius: @btn-border-radius-base;
  }

  &-sm {
    >.@{btnClassName}:only-child {
      border-radius: @btn-border-radius-sm;
    }

    >span:only-child>.@{btnClassName} {
      border-radius: @btn-border-radius-sm;
    }

    >.@{btnClassName}:first-child:not(:last-child),
    >span:first-child:not(:last-child)>.@{btnClassName} {
      border-bottom-left-radius: @btn-border-radius-sm;
      border-top-left-radius: @btn-border-radius-sm;
    }

    >.@{btnClassName}:last-child:not(:first-child),
    >span:last-child:not(:first-child)>.@{btnClassName} {
      border-bottom-right-radius: @btn-border-radius-sm;
      border-top-right-radius: @btn-border-radius-sm;
    }
  }

  &>& {
    float: left;
  }

  &>&:not(:first-child):not(:last-child)>.@{btnClassName} {
    border-radius: 0;
  }

  &>&:first-child:not(:last-child) {
    >.@{btnClassName}:last-child {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
      padding-right: 8px;
    }
  }

  &>&:last-child:not(:first-child)>.@{btnClassName}:first-child {
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
    padding-left: 8px;
  }
}